//index.js
var api = require('../../utils/api.js');
//   wx.openSetting({

//   });

// wx.getSetting({
//   success: (res) => {

//     if (!res.authSetting['scope.record']) {
//       wx.authorize({
//         scope: 'scope.record',
//         success() {
//           // 用户已经同意小程序使用录音功能，后续调用 wx.startRecord 接口不会弹窗询问
//           wx.startRecord()
//         }
//       })
//     }

//     if (!res.authSetting['scope.camera']) {
//       wx.authorize({
//         scope: 'scope.camera',
//         success() {
//         }
//       })
//     }

//   }
// });

Page({
  data: {
    
  },
  onLoad(params) {
    this.params = params;
  },

  formSubmit(e) {
    var wx = wx;
    api.post({
      url: 'Login/signIn',
      data: e.detail.value,
      success: data => {
        if (data.code == 200) {
          wx.setStorage({
            key: "userbaseinfo",
            data: data,
            success:function(res){
              console.log('存储'+res.data);
              wx.navigateTo({
                url: '../home/home'
              });
            },
            fail:function(res){
              console.log(res);
            },
            complete:function(res){
              console.log(res);
            }
          });
          // data.tim
          // data.token
          // data.udid
          wx.showToast({
            title: data.data.message,
            icon: 'success',
            duration: 1000
          });

        }else{
          wx.showModal({
            content: data.data.message,
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              }
            }
          })
        }
        console.log(data);
      }
    });
  },
  onMobileInput(e) {
    this.phone = e.detail.value;
  },
  onGetVerificationCode() {
    api.post({
      url: 'Login/code',
      data: { phone: this.phone},
      success: data => {
        if (data.code == 200) {
          wx.showModal({
            content: data.data.message,
            showCancel: false,
            success: function (res) {
            }
          });
        } else {
          wx.showModal({
            content: data.data.message,
            showCancel: false,
            success: function (res) {
              
            }
          });
        }
        console.log(data);
      }
    });
  }
});